package com.calms.study.infra.service;

//import com.hulunbuir.study.druid.config.druid_many_datasource.DataSource;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.calms.study.infra.dto.DbOneDTO;
import com.calms.study.infra.entity.DbOne;
import com.calms.study.infra.mapper.DbOneMapper;
import com.calms.study.infra.vo.DbOneVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 临时表
 *
 * @author code@code.com
 * @date 2024-11-19 12:09:39
 */
@DS("one")
@Slf4j
@Service
public class DbOneServiceImpl implements DbOneService {

    @Autowired
    private DbOneMapper mapper;

    /**
     * 使用指定的数据源, 并指定对应的数据库事务管理器
     */
    @Override
//    @DataSource(value = "one")
//    @Transactional(rollbackFor = Exception.class, transactionManager = "oneDataSourceTransactionManager")
    @Transactional(rollbackFor = Exception.class)
    public DbOneVO saveTestData(DbOneDTO dbOneDTO) {
        DbOne dbOne = new DbOne();
        BeanUtils.copyProperties(dbOneDTO, dbOne);

        mapper.insert(dbOne);
        DbOneVO tempTableVO = new DbOneVO();
        BeanUtils.copyProperties(dbOne, tempTableVO);
        return tempTableVO;
    }

    @Override
//    @DataSource(value = "one")
    public List<DbOneVO> pageParams(DbOneDTO dbOneDTO) {
        return mapper.page(dbOneDTO);
    }

}
